<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div {
            padding: 10px;
            margin: 30px;
            border: 1px solid brown;
        }
        span {
            border: 1px dashed red;
            margin: 10px;
        }
    </style>
</head>
<body>
    <div>1<hr></div>
    <div>2<hr></div>
    <div>3<hr></div>
    <div>4<hr></div>
    <div>5<hr></div>
    <div>6<hr></div>
</body>
<script src="js/itcast.core.js"></script>
<script src="js/itcast.dom.js"></script>
<script src="js/itcast.ctor.js"></script>
<script>
    var arr = [],
        push = arr.push;
    /*Itcast.fn.appendTo = function(dom){
        dom.appendChild( this[ 0 ] );
        return this;
    }*/

    /*Itcast.fn.appendTo = function(dom){
        this.each(function(i,v){
            return dom.appendChild( this );
        });
        return this;
    }*/

    /*Itcast.fn.appendTo = function(doms){
        return this.each(function(i,v){
            for ( var i = 0 ; i < doms.length ; i++ ) {
                doms[i].appendChild( i === doms.length -1 ? this : this.cloneNode(true) );
            }
        });
    }*/
    Itcast.fn.appendTo = function( selector ){
        var iObj = Itcast( selector ),
            len = iObj.length,
            i;
        return this.each(function(i,v){
            for ( i = 0 ; i < len ; i++ ) {
                iObj[i].appendChild( i === len -1
                                            ? this
                                            : this.cloneNode(true) );
            }
        });
    }



</script>

<script>

    // 1.加入传入的是一个dom元素
    var div = I('div').get( 0 );
    I('<p>p1</p>').appendTo( I('div').get( 0 ) );



    // 2.传入的是一个选择器
    I('<p>p2</p>').appendTo( 'div' );

    // 3.传入的也是一个 Itcast 对象
    // 在P标签中加入 span 标签



</script>


</html>